package com.jdd.modules.userOptionLog.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jdd.common.api.vo.Result;
import com.jdd.common.util.LoginUserUtils;
import com.jdd.dao.service.TDeviceCmdRequestService;
import com.jdd.modules.userOptionLog.entity.TUserOptionLog;
import com.jdd.modules.userOptionLog.service.ITUserOptionLogService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ls
 * @since 2022-10-25
 */
@RestController
@RequestMapping("/optionLog")
public class TUserOptionLogController {

    @Resource
    private ITUserOptionLogService optionLogService;

    @Resource
    private TDeviceCmdRequestService cmdRequestService;


    @GetMapping(value = "/list")
    public Result<IPage<TUserOptionLog>> list(TUserOptionLog tUserOptionLog, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo) {
        Result<IPage<TUserOptionLog>> result = new Result<IPage<TUserOptionLog>>();
        List<String> projectCodeList = LoginUserUtils.getProjectCodeList();
        if (projectCodeList.isEmpty()){
            result.setSuccess(true);
            return result;
        }
        Page<TUserOptionLog> page = new Page<TUserOptionLog>(pageNo, pageSize);
        IPage<TUserOptionLog> iPage = optionLogService.findList(page,tUserOptionLog,projectCodeList);
        result.setSuccess(true);
        result.setResult(iPage);
        return result;
    }
}
